package com.probox.common.entity.service.wechat.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.Arrays;
import java.util.List;

import com.probox.common.core.enums.DataStatus;
import com.probox.common.core.utils.SecurityUtils;
import com.probox.common.core.utils.StringUtils;
import com.probox.common.entity.domain.wechat.broadcast.Good;
import com.probox.common.entity.mapper.wechat.WechatBroadcastProductMapper;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.probox.common.entity.mapper.wechat.WechatBroadcastProductMiddleMapper;
import com.probox.common.entity.domain.wechat.broadcast.WechatBroadcastProductMiddle;
import com.probox.common.entity.service.wechat.IWechatBroadcastProductMiddleService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 直播间、商品关系Service业务层处理
 *
 * @author usoft
 * @date 2021-07-26
 */
@Service
@Transactional
public class WechatBroadcastProductMiddleServiceImpl extends ServiceImpl<WechatBroadcastProductMiddleMapper, WechatBroadcastProductMiddle> implements IWechatBroadcastProductMiddleService {
    @Autowired
    private WechatBroadcastProductMiddleMapper wechatBroadcastProductMiddleMapper;

    @Autowired
    private WechatBroadcastProductMapper wechatBroadcastProductMapper;


    /**
     * 查询直播间、商品关系
     *
     * @param id 直播间、商品关系ID
     * @return 直播间、商品关系
     */
    @Override
    public WechatBroadcastProductMiddle selectWechatBroadcastProductMiddleById(Long id) {
        return this.getById(id);
    }

    /**
     * 查询直播间、商品关系列表
     *
     * @param wechatBroadcastProductMiddle 直播间、商品关系
     * @return 直播间、商品关系
     */
    @Override
    public List<WechatBroadcastProductMiddle> queryList(WechatBroadcastProductMiddle wechatBroadcastProductMiddle) {
        QueryWrapper<WechatBroadcastProductMiddle> queryWrapper = Wrappers.query();
        if (StringUtils.isNotEmpty(String.valueOf(wechatBroadcastProductMiddle.getId())) && wechatBroadcastProductMiddle.getId() != null) {
            queryWrapper.eq("ID", wechatBroadcastProductMiddle.getId());
        }
        if (StringUtils.isNotEmpty(String.valueOf(wechatBroadcastProductMiddle.getRoomId())) && wechatBroadcastProductMiddle.getRoomId() != null) {
            queryWrapper.eq("BROADCAST_ID", wechatBroadcastProductMiddle.getRoomId());
        }
        if (StringUtils.isNotEmpty(String.valueOf(wechatBroadcastProductMiddle.getProductId())) && wechatBroadcastProductMiddle.getProductId() != null) {
            queryWrapper.eq("PRODUCT_ID", wechatBroadcastProductMiddle.getProductId());
        }
        if (StringUtils.isNotEmpty(String.valueOf(wechatBroadcastProductMiddle.getGoodsId())) && wechatBroadcastProductMiddle.getGoodsId() != null) {
            queryWrapper.eq("GOODS_ID", wechatBroadcastProductMiddle.getGoodsId());
        }
        if (StringUtils.isNotEmpty(String.valueOf(wechatBroadcastProductMiddle.getDataStatus())) && wechatBroadcastProductMiddle.getDataStatus() != null) {
            queryWrapper.eq("DATA_STATUS", wechatBroadcastProductMiddle.getDataStatus());
        }
        return wechatBroadcastProductMiddleMapper.selectList(queryWrapper);
    }

    /**
     * 新增直播间、商品关系
     *
     * @param wechatBroadcastProductMiddle 直播间、商品关系
     * @return 结果
     */
    @Override
    public boolean insertWechatBroadcastProductMiddle(WechatBroadcastProductMiddle wechatBroadcastProductMiddle) {

        return this.save(wechatBroadcastProductMiddle);

    }

    /**
     * 修改直播间、商品关系
     *
     * @param wechatBroadcastProductMiddle 直播间、商品关系
     * @return 结果
     */
    @Override
    public boolean updateWechatBroadcastProductMiddle(WechatBroadcastProductMiddle wechatBroadcastProductMiddle) {

        return this.updateById(wechatBroadcastProductMiddle);
    }

    /**
     * 批量删除直播间、商品关系
     *
     * @param ids 需要删除的直播间、商品关系ID
     * @return 结果
     */
    @Override
    public boolean deleteWechatBroadcastProductMiddleByIds(Long[] ids) {
        return this.removeByIds(Arrays.asList(ids));
    }

    /**
     * 查询直播间下商品
     * @param roomId
     * @return
     */
    @Override
    public List<Good> getBroadcastMiddle(Long roomId) {
        return  wechatBroadcastProductMiddleMapper.selectBroadcastMiddle(roomId,SecurityUtils.getPlatformId());
    }


}
